package java_jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;

import util.DBUtil;

/*
 * 4:用 PreparedStatement 实现删除功能（表随意）
 */
public class jdbc6 {

	public static void main(String[] args) {
		Connection con = DBUtil.getConnection();
		PreparedStatement pst = null;
		Scanner in = new Scanner(System.in);

		System.out.println("请输入您要删除的学号：");
		long stuno = in.nextLong();
		try {

			String sql = "delete from s_student where stuno= ?";
			pst = con.prepareStatement(sql);
			pst.setLong(1, stuno);

			pst.executeUpdate();
			System.out.println("删除成功");

		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {

			DBUtil.close(pst);
			DBUtil.close(con);

		}
	}

}